package com.yuetong.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuetong.common.annotation.Log;
import com.yuetong.common.core.controller.BaseController;
import com.yuetong.common.core.domain.AjaxResult;
import com.yuetong.common.enums.BusinessType;
import com.yuetong.business.domain.YtPartner;
import com.yuetong.business.service.IYtPartnerService;
import com.yuetong.common.utils.poi.ExcelUtil;
import com.yuetong.common.core.page.TableDataInfo;

/**
 * 合作单位Controller
 *
 * @author  卓晓君
 * @date 2025-03-20
 */
@RestController
@RequestMapping("/business/partner")
public class YtPartnerController extends BaseController
{
    @Autowired
    private IYtPartnerService ytPartnerService;

    /**
     * 查询合作单位列表
     */
    @PreAuthorize("@ss.hasPermi('business:partner:list')")
    @GetMapping("/list")
    public TableDataInfo list(YtPartner ytPartner)
    {
        startPage();
        List<YtPartner> list = ytPartnerService.selectYtPartnerList(ytPartner);
        return getDataTable(list);
    }

    /**
     * 导出合作单位列表
     */
    @PreAuthorize("@ss.hasPermi('business:partner:export')")
    @Log(title = "导出合作单位列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YtPartner ytPartner)
    {
        List<YtPartner> list = ytPartnerService.selectYtPartnerList(ytPartner);
        ExcelUtil<YtPartner> util = new ExcelUtil<YtPartner>(YtPartner.class);
        util.exportExcel(response, list, "合作单位数据");
    }

    /**
     * 获取合作单位详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:partner:query')")
    @GetMapping(value = "/{partnerId}")
    public AjaxResult getInfo(@PathVariable("partnerId") Long partnerId)
    {
        return success(ytPartnerService.selectYtPartnerByPartnerId(partnerId));
    }

    /**
     * 新增合作单位
     */
    @PreAuthorize("@ss.hasPermi('business:partner:add')")
    @Log(title = "合作单位", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YtPartner ytPartner)
    {
        return toAjax(ytPartnerService.insertYtPartner(ytPartner));
    }

    /**
     * 修改合作单位
     */
    @PreAuthorize("@ss.hasPermi('business:partner:edit')")
    @Log(title = "合作单位", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YtPartner ytPartner)
    {
        return toAjax(ytPartnerService.updateYtPartner(ytPartner));
    }

    /**
     * 删除合作单位
     */
    @PreAuthorize("@ss.hasPermi('business:partner:remove')")
    @Log(title = "合作单位", businessType = BusinessType.DELETE)
	@DeleteMapping("/{partnerIds}")
    public AjaxResult remove(@PathVariable Long[] partnerIds)
    {
        return toAjax(ytPartnerService.deleteYtPartnerByPartnerIds(partnerIds));
    }
}
